package com.wh.message.controller;

import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 欢迎界面
 * @author 谢泽鹏
 * @version V1.0
 * @Package com.wh.message.mongo.service.impl
 * @date 2014年10月8日 下午4:02:14
 * @Copyright 个人版权所有
 * @Company 贵州万华科技有限公司Copyright (c) 2018
 */
@Controller
public class WelcomeController {


    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @RequestMapping(value = "index")
    public String index(){
        return "index";
    }


    @RequestMapping(value = "getKong")
    public void getKong(HttpServletRequest request, HttpServletResponse response){
        CommonResult commonResult = new CommonResult();
        try{
            response.setCharacterEncoding("UTF-8");
            response.setContentType("application/json;charset=UTF-8");
            String x_consumer_id = request.getHeader("x-consumer-id");
            String x_consumer_username = request.getHeader("x-consumer-username");
            logger.info("获取消息-->>x_consumer_id:  " + x_consumer_id);
            logger.info("获取消息-->>x_consumer_username:  " + x_consumer_username);
            if("ancheel".equalsIgnoreCase(x_consumer_username)){
                commonResult.setCode("200");
                commonResult.setMessage("获取消息成功");
                commonResult.setResult("获取成功消息是############XXXXXX");
            }else{
                commonResult.setCode("500");
                commonResult.setMessage("获取消息失败");
                commonResult.setResult(new JSONObject());
            }
            response.getWriter().flush();
            response.getWriter().print(JsonUtil.Json2All(commonResult));
        } catch (Exception e){
                e.printStackTrace();
        }
    }

}
